package com.gk.panda.apis.patrol.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gk.panda.apis.patrol.commons.StateEnum;
import com.gk.panda.apis.patrol.servicr.ReportResourceService;
import com.gk.panda.apis.patrol.servicr.ReportService;
import com.gk.panda.commons.result.Result;
import com.gk.panda.pojo.patrol.dto.*;
import com.gk.panda.pojo.patrol.entity.ReportResourceEntity;
import com.gk.panda.pojo.patrol.request.PageReportRequest;
import com.gk.panda.pojo.patrol.request.PatrolQueryPageRequest;
import com.gk.panda.pojo.patrol.request.UpdatePatrolRequest;
import com.gk.panda.pojo.patrol.request.UpdateReportRequest;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotNull;

/**
 * @Author：xxz
 * @Create: 2022/11/1 16:23
 */
@RestController
@RequestMapping("/report")
@Api(tags = "巡护事件管理台相关接口")
public class ReportController {

    @Resource
    private ReportService reportService;


    @GetMapping("/page")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "totalOrg", value = "所属机构"),
            @ApiImplicitParam(name = "CreateTimeEnd", value = "事件时间"),
            @ApiImplicitParam(name = "CreateTimeStart", value = "事件时间"),
            @ApiImplicitParam(name = "people", value = "巡护人员"),
            @ApiImplicitParam(name = "patrolType", value = "巡护类型"),
            @ApiImplicitParam(name = "reportType", value = "事件分类"),
            @ApiImplicitParam(name = "pageNo", value = "页码"),
            @ApiImplicitParam(name = "pageSize", value = "页面大小")
    })
    @ApiOperation("分页查询")
    public Result<Page<ReportPageDTO>> queryPage(PageReportRequest request) {
        return Result.ok(reportService.queryPage(request));
    }

    @GetMapping("/detail")
    @ApiOperation("查询详情")
    public Result<ReportDetailDTO> detail(@NotNull @RequestParam Long reportId) {
        return Result.ok(reportService.detail(reportId));
    }
    @PutMapping("/update")
    @ApiOperation("修改事件")
    public Result<?> update(@Validated @RequestBody UpdateReportRequest request){
        return reportService.update(request);
    }
    @DeleteMapping("/delete")
    @ApiOperation("删除事件")
    public Result<?> delete(@NotNull @RequestParam Long id) {
        return reportService.remove(id);
    }

    @ApiOperation("导出巡护事件信息")
    @GetMapping("/export")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "totalOrg", value = "所属机构"),
            @ApiImplicitParam(name = "CreateTimeEnd", value = "事件时间"),
            @ApiImplicitParam(name = "CreateTimeStart", value = "事件时间"),
            @ApiImplicitParam(name = "people", value = "巡护人员"),
            @ApiImplicitParam(name = "patrolType", value = "巡护类型"),
            @ApiImplicitParam(name = "reportType", value = "事件分类"),
            @ApiImplicitParam(name = "pageNo", value = "页码"),
            @ApiImplicitParam(name = "pageSize", value = "页面大小")
    })
    private void export(HttpServletResponse response, PageReportRequest request){
        try {
            reportService.export(response,request);
        }catch (Exception e){
            e.printStackTrace();
            throw new RuntimeException("导出巡护事件信息失败");
        }
    }

    @GetMapping("/count")
    @ApiOperation("巡护统计")
    private Result<ReportSumDTO> count(PageReportRequest request){
        return Result.ok(reportService.countData(request));
    }
    @GetMapping("/updateDetail")
    @ApiOperation("查询事件修改详情")
    public Result<UpdateDetailDTO> updateDetail(@RequestParam("id") Long id) {
        return Result.ok(reportService.updateDetail(id));
    }
}
